// 读取目录的内容。

#include "error.h"

#include <stdio.h>
#include <errno.h>

#include <dirent.h>

int
main(int argc, char **argv)
{
    DIR *d;
    struct dirent *e;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s directory\n", argv[0]);
        return 1;
    }

    d = opendir(argv[1]);
    if (d == NULL) {
        unix_error("opendir fail");
        return 1;
    }

    while ((e = readdir(d)) != NULL) {
        printf("Found file:%s\n", e->d_name);
    }

    if (errno != 0)
        unix_error("readdir fail");

    closedir(d);
    return 0;
}

